#include <stdio.h>

#define SIZE 8

typedef float elem_t;

int cmp_float_ascend(float a, float b)
{
	return a > b;
}

int cmp_float_descend(float a, float b)
{
	return a < b;
}

void sort(elem_t* arr, int cnt, int (*cmp)(elem_t, elem_t));

int main(void)
{
	int i;

	elem_t arr[SIZE] = { 5, 45, 9, 67, 7, 42, 31, 20 };

	sort(arr, SIZE, cmp_float_descend);

	for (i = 0; i < SIZE; i++) {
		printf("%.2f ", arr[i]);
	}
	printf("\n");

	sort(arr, SIZE, cmp_float_ascend);

	for (i = 0; i < SIZE; i++) {
		printf("%.2f ", arr[i]);
	}
	printf("\n");

	return 0;
}

void sort(elem_t* arr, int cnt, int (*cmp)(elem_t, elem_t))
{
	int i, j;
	elem_t t;

	for (i = 0; i < cnt - 1; i++) {
		for (j = 0; j < cnt - i - 1; j++) {
			if (cmp(arr[j], arr[j + 1])) {
				t = arr[j];
				arr[j] = arr[j + 1];
				arr[j + 1] = t;
			}
		}
	}
}
